package kr.saeildamil.androidstudy.ch16;

import kr.saeildamil.androiddforstudy.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

public class Ch16_Popup extends Activity {
	PopupWindow popup;
	View popupview;
	LinearLayout layout;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_popup);
		
		layout = (LinearLayout) findViewById(R.id.ch16_popup_layout);
		popupview = View.inflate(this, R.layout.ch16_popupview, null);
		popup = new PopupWindow(popupview, 200, 150, true);
		
		final Button showbtn = (Button) findViewById(R.id.ch16_popup_showbtn);
		showbtn.setOnClickListener(new Button.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// 지정한 좌표에
				popup.showAtLocation(layout, Gravity.NO_GRAVITY, 100, 150);
				// 가운데
				//popup.showAtLocation(layout, Gravity.CENTER, 0, 0);
				// 가운데 + 50,80
				//popup.showAtLocation(layout, Gravity.CENTER, 50, 80);
				// 화면 벗어나기
				//popup.showAtLocation(layout, Gravity.NO_GRAVITY, 800, 1200);
				// 수평 중앙, 수직 바닥
				//popup.showAtLocation(layout, Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 0, 0);
				// 수평 중앙, 수직 바닥 + 50,50
				//popup.showAtLocation(layout, Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 50, 50);
				// 버튼 아래에 놓기
				//popup.setAnimationStyle(-1);
				//popup.showAsDropDown(showbtn);
			}
		});
		Button closebtn = (Button) popupview.findViewById(R.id.ch16_popup_closebtn);
		closebtn.setOnClickListener(new Button.OnClickListener() {
			
			public void onClick(View v) {
				popup.dismiss();
			}
		});
	}
}
